package com.member.shop.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.member.shop.domain.ActivityFieldData;
import com.member.shop.domain.SysBizActivityField;
import com.member.shop.mapper.SysBizActivityFieldMapper;
import com.member.shop.service.ISysBizActivityFieldService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 活动报名字段Service业务层处理
 *
 * @author wangxin
 * @date 2024-06-14
 */
@Service
public class SysBizActivityFieldServiceImpl extends ServiceImpl<SysBizActivityFieldMapper, SysBizActivityField> implements ISysBizActivityFieldService {
    @Resource
    private SysBizActivityFieldMapper sysBizActivityFieldMapper;

    /**
     * 查询活动报名字段
     *
     * @param id 活动报名字段主键
     * @return 活动报名字段
     */
    @Override
    public SysBizActivityField selectSysBizActivityFieldById(Long id) {
        SysBizActivityField sysBizActivityField = sysBizActivityFieldMapper.selectById(id);
        sysBizActivityField.setFieldList(JSON.parseArray(sysBizActivityField.getInfo(), ActivityFieldData.class));
        return sysBizActivityField;
    }

    /**
     * 查询活动报名字段列表
     *
     * @param sysBizActivityField 活动报名字段
     * @return 活动报名字段
     */
    @Override
    public List<SysBizActivityField> selectSysBizActivityFieldList(LambdaQueryWrapper<SysBizActivityField> queryWrapper) {
        return sysBizActivityFieldMapper.selectList(queryWrapper);
    }

    /**
     * 新增活动报名字段
     *
     * @param sysBizActivityField 活动报名字段
     * @return 结果
     */
    @Override
    public int insertSysBizActivityField(SysBizActivityField sysBizActivityField) {
        sysBizActivityField.setInfo(JSON.toJSONString(sysBizActivityField.getFieldList()));
        return sysBizActivityFieldMapper.insert(sysBizActivityField);
    }

    /**
     * 修改活动报名字段
     *
     * @param sysBizActivityField 活动报名字段
     * @return 结果
     */
    @Override
    public int updateSysBizActivityField(SysBizActivityField sysBizActivityField) {
        sysBizActivityField.setInfo(JSON.toJSONString(sysBizActivityField.getFieldList()));
        return sysBizActivityFieldMapper.updateById(sysBizActivityField);
    }

    /**
     * 批量删除活动报名字段
     *
     * @param ids 需要删除的活动报名字段主键
     * @return 结果
     */
    @Override
    public int deleteSysBizActivityFieldByIds(Long[] ids) {
        return sysBizActivityFieldMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除活动报名字段信息
     *
     * @param id 活动报名字段主键
     * @return 结果
     */
    @Override
    public int deleteSysBizActivityFieldById(Long id) {
        return sysBizActivityFieldMapper.deleteById(id);
    }
}
